<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Users_Entity extends CI_Model
{
    private $tablename = 'users';
    private $id = null;
    private $username = null;
    private $firtname = null;
    private $lastname = null;
    private $image = null;
    private $pass = null;
    private $create = null;
    private $gid = null;
    private $createby = null;
    private $locked = null;
    private $idel = null;
    private $acti = null;
    
    public function setId($Id)
    {
        $this->id = $Id;
    }

    public function setUsername($Username)
    {
        $this->username = $Username;
    }

    public function setFirtname($Firtname)
    {
        $this->firtname = $Firtname;
    }

    public function setLastname($Lastname)
    {
        $this->lastname = $Lastname;
    }

    public function setImage($Image)
    {
        $this->image = $Image;
    }

    public function setPass($Pass)
    {
        $this->pass = $Pass;
    }

    public function setCreate($Create)
    {
        $this->create = $Create;
    }

    public function setGid($Gid)
    {
        $this->gid = $Gid;
    }

    public function setCreateby($Createby)
    {
        $this->createby = $Createby;
    }

    public function setLocked($Locked)
    {
        $this->locked = $Locked;
    }

    public function setIdel($Idel)
    {
        $this->idel = $Idel;
    }

    public function setActi($Acti)
    {
        $this->acti = $Acti;
    }

    public function save()
    {
        $params = array();
        foreach ($this as $key => $val) {
            if ($key == 'tablename') continue;
            if ($val == null || $val == '') continue;
            $params[$key] = $val;
        }
                
        if (!isset($params['id'])) {
            if ($this->db->insert($this->tablename, $params)) {
                return $this->db->insert_id();
            } else {
                return 0;
            }
        } else {
            return $this->db->update($this->tablename, $params, array('id' => $params['id']));
        }
        
    }
    
    public function del($id)
    {
        
        return $this->db->delete($this->tablename, array('id' => $id));    
    }
    
    public function getUsersById($id)
    {
        return $this->db->get_where($this->tablename, array('id' => $id));
    }
    
    public function getAllList()
    {
        return $this->db->get($this->tablename);
    }
    
    public function TotalUsers()
    {
        return $this->db->count_all_results('Users'); 
    } 
}       
        